// -------------------------------------------------------------
// api: respool.area.create
// time: 2020-07-30
// author: minner
// -------------------------------------------------------------
exports['respool.area.create'] = obj_api = {
    '1.0': function (args, session, callback) {
        if (!session.account_id) {
            return callback(12, null, '会话已失效');
        }

        if (!args.respool_id || typeof args.respool_id != 'number') {
            return callback(11, null, '缺少参数(respool_id)');
        }
        if (!args.respool_area_name || typeof args.respool_area_name != 'string') {
            return callback(11, null, '缺少参数(respool_area_name)');
        }
        if (!args.console_redis_host || typeof args.console_redis_host != 'string') {
            return callback(11, null, '缺少参数(console_redis_host)');
        }
        if (typeof args.console_redis_port != 'number' || args.console_redis_port < 0 || args.console_redis_port > 65535) {
            return callback(11, null, '缺少参数(console_redis_port)');
        }
        if (!args.console_redis_password || typeof args.console_redis_password != 'string') {
            return callback(11, null, '缺少参数(console_redis_password)');
        }
        if (!args.description || typeof args.description != 'string') {
            return callback(11, null, '缺少参数(description)');
        }

        let sql_insert = "INSERT INTO `deploy_respool_area`" +
            " (`respool_area_name`, `console_redis_host`, `console_redis_port`, `console_redis_password`, `create_time`, `creator`, `status`, `description`, `respool_id`)" +
            " VALUES (" +
            mysql.escape(args.respool_area_name) + ", " +
            mysql.escape(args.console_redis_host) + ", " +
            args.console_redis_port + ", " +
            mysql.escape(args.console_redis_password) + ", '" +
            uim.dateTime() + "', " +
            session.account_id + ", '1', " +
            mysql.escape(args.description) + ", " +
            args.respool_id + ")";

        uim.db_query(sql_insert, function (err, results, fields) {
            if (err) {
                return callback(6, null, '数据库查询出错：' + err);
            }
            callback(0, {
                respool_area_id: results.insertId,
            });
        });
    },

};
